import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutterapp/bean/NavigatorData.dart';
import 'package:flutterapp/widget/WAppbar.dart';
import 'package:flutterapp/widget/WButton.dart';
import 'package:flutterapp/widget/WColumn.dart';
import 'package:flutterapp/widget/WDialog.dart';
import 'package:flutterapp/widget/WImg.dart';
import 'package:flutterapp/widget/WInput.dart';
import 'package:flutterapp/widget/WLayout.dart';
import 'package:flutterapp/widget/WList.dart';
import 'package:flutterapp/widget/WNavigator.dart';
import 'package:flutterapp/widget/WRow.dart';
import 'package:flutterapp/widget/WScaffold.dart';
import 'package:flutterapp/widget/WSize.dart';
import 'package:flutterapp/widget/WStack.dart';
import 'package:flutterapp/widget/WText.dart';
import 'package:flutterapp/widget/WWrap_Flow.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    debugPaintSizeEnabled = false; //显示边界布局然后自动import即可
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var listContent = List<NavigatorData>();

  void _incrementCounter() {
    setState(() {});
  }

  /**
   * 等于android 的 onCreateView()
   */
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    initData();
  }

  /**
   * 1、在初始化initState后执行； 2、显示/关闭其它widget。 3、可执行多次；
   */
  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
  }

  /**
   * 有点像Android的onStop函数， 在打开新的Widget或回到这个widget时会执行； 可执行多次；
   */
  @override
  void deactivate() {
    // TODO: implement deactivate
    super.deactivate();
  }

  /**
   * 类似于Android的onDestroy， 在执行Navigator.pop后会调用该办法， 表示组件已销毁；
   */
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

  void initData() {
    listContent.add(NavigatorData("文本组件", WText()));
    listContent.add(NavigatorData("按钮组件", WButton()));
    listContent.add(NavigatorData("图片组件", WImg()));
    listContent.add(NavigatorData("输入框组件", WInput()));
    listContent.add(NavigatorData("ListView组件", WList()));
    listContent.add(NavigatorData("AppBar组件", WAppbar()));
    listContent.add(NavigatorData("Scaffold组件", WScaffold()));
    listContent.add(NavigatorData("Navigator组件", WNavigator()));
    listContent.add(NavigatorData("row组件", WRow()));
    listContent.add(NavigatorData("column组件", WColumn()));
    listContent.add(NavigatorData("流式布局", WWarpFlow()));
    listContent.add(NavigatorData("层叠布局", WStack()));
    listContent.add(NavigatorData("布局例子", WLayout()));
    listContent.add(NavigatorData("Dialog组件", WDialog()));
    listContent.add(NavigatorData("尺寸限制组件", WSize()));
  }

  Widget _itemView(NavigatorData data, int index) {
    return InkWell(
      onTap: () {
        print(index);
        Navigator.push(context, MaterialPageRoute(builder: (context) {
          Object obj = data.object;
          return obj;
        }));
      },
      child: Container(
        margin: EdgeInsets.all(10),
        height: 60,
        decoration: BoxDecoration(
            border: Border.all(color: Colors.black, width: 1),
            borderRadius: BorderRadius.circular(3)),
        alignment: Alignment.center,
        child: Text(
          "${data.name}",
          style: TextStyle(color: Colors.black),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Container(
          child: ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          return _itemView(listContent[index], index);
        },
        itemCount: listContent.length,
      )),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
